function out = normalizeDistanceAxis(in, x0, x1)
% normalizeDistanceAxis
%
% Called by laminarBeadDistributionAnalysis
%
% Usage and syntax:
% IN -- vector, e.g. 1 to 550, typically the pixel values;
% this function transforms it to give a vector
% in terms of the normalized cortical depth.
% x0 -- index in IN corresponding to the pia
% x1 -- index corresponding to white matter

% gs feb 2008
% ----------------------------
v = in; 

% first make a normalized version of v, 0 to 1
v = 0 : numel(v) - 1;
v = v / max(v);

% now calculate the slope and apply
% a = (y1 - y0) / (x1 - x0)
slope = (in(end) - in(1)) / (x1 - x0);
v = v * slope;

% now determine the offset and apply
% y = ax+b
% 0 = slope * (x0 / length(v)) + offset
offset = -slope * (x0 / length(v));

v = v + offset;

out = v;